package cn.zwx.member.svc.fallback;

import cn.zwx.base.entity.ResponseEntity;
import cn.zwx.base.enums.ResponseCodeEnum;
import cn.zwx.base.exception.BizWrapException;
import cn.zwx.member.svc.fallback.AddressApiFallback;
import cn.zwx.member.svc.facade.DsitrictsServiceApi;
import cn.zwx.member.svc.dto.DsitrictsListDTO;
import cn.zwx.member.svc.vo.DsitrictsListVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zhangwenxue
 */
@Component
public class DsitrictsApiFallback implements FallbackFactory<DsitrictsServiceApi> {
    private static final Logger logger = LoggerFactory.getLogger(AddressApiFallback.class);

    @Override
    public DsitrictsServiceApi create(Throwable cause) {
        logger.error("调用Member-Service fallback",cause);
        return new DsitrictsServiceApi() {
            @Override
            public ResponseEntity<List<DsitrictsListVO>> getDistrictsList(DsitrictsListDTO dto) throws BizWrapException {
                logger.error("getDistrictsList fallback",cause);
                return ResponseEntity.fail(ResponseCodeEnum.RPC_ERROR.getCode(),cause.getMessage());
            }

            @Override
            public DsitrictsApiFallback create(Throwable cause) {
                logger.error("调用Member-Service fallback",cause);
                return null;
            }
        };
    }
}
